﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 输入控制
/// /// </summary>
public class InputMgr : BaseManager<InputMgr>
{

    private bool isStart = false;
    public InputMgr()
    {
        MonoMgr.GetInstance().AddUpdateListener(MyUpdate);

    }
    public void StartOrEndCheck(bool isOpen)
    {
        isStart = isOpen;
    }

    /// <summary>
    /// 用来检测按键抬起按下
    /// </summary>
    /// <param name="key">按键 KeyCode 类型</param>
    private void CheckKeyCode(KeyCode key)
    {
        if (Input.GetKeyUp(key))
        {
            EventService.EventTrigger<KeyCode>(E_Event_Type.KeyUp, key);
        }
        else if (Input.GetKeyDown(key))
        {
            EventService.EventTrigger<KeyCode>(E_Event_Type.KeyDown, key);
        }
        else if (Input.GetKey(key))
        {
            EventService.EventTrigger<KeyCode>(E_Event_Type.Key, key);
        }
    }
    private void CheckKeyCodeTow(KeyCode key1, KeyCode key2)
    {
        if (Input.GetKeyDown(key1))
        {
            if (Input.GetKeyDown(key2))
            {
                EventService.EventTrigger<KeyCode, KeyCode>(E_Event_Type.TwoKeyDown, key1, key2);
            }
        }
    }
    private void MyUpdate()
    {
        if (!isStart)
            return;
        if (GameManager.GetInstance().Game_State == E_Game_State.Idle)
            CheckKeyCode(KeyCode.Space);
        if (GameManager.GetInstance().Game_State == E_Game_State.Ready)
            CheckKeyCode(KeyCode.O);
        if (GameManager.GetInstance().Game_State == E_Game_State.End)
            CheckKeyCode(KeyCode.Space);
    }
}
